import Vue from 'vue';
import VueRouter from 'vue-router';
import Home from '../views/Home.vue';
import Demo from '../views/Demo.vue';

Vue.use(VueRouter);

const routes = [
  // demo
  {
    path: '/demo',
    name: 'Demo',
    component: Demo,
  },
  // 主页
  {
    path: '/',
    name: 'Home',
    component: Home,
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
  },
  // 登录页
  {
    path: '/login',
    name: 'Login',
    component: () => import(/* webpackChunkName: "login" */ '../views/Login.vue'),
  },
  // 搜索页
  {
    path: '/search',
    name: 'Search',
    component: () => import(/* webpackChunkName: "search" */ '../views/Search.vue'),
  },
  // 定制页
  {
    path: '/custom',
    name: 'Custom',
    component: () => import(/* webpackChunkName: "custom" */ '../views/Custom.vue'),
  },
  // 定制页
  {
    path: '/graduation',
    name: 'Graduation',
    component: () => import(/* webpackChunkName: "graduation" */ '../views/Graduation.vue'),
  },
  // 游记列表页
  {
    path: '/notes',
    name: 'Notes',
    component: () => import(/* webpackChunkName: "about" */ '../views/Notes.vue'),
  },
  // 游记详情页
  {
    path: '/articles/:tid',
    name: 'Articles',
    props: true,
    component: () => import(/* webpackChunkName: "about" */ '../views/Articles.vue'),
  },
  // 商品列表页
  {
    path: '/travelMall',
    name: 'TravelMall',
    component: () => import(/* webpackChunkName: "travelMall" */ '../views/TravelMall.vue'),
  },
  // 商品详情页
  {
    path: '/tourMdetails/:gid',
    name: 'TourMdetails',
    props: true,
    component: () => import(/* webpackChunkName: "tourMdetails" */ '../views/TourMdetails.vue'),
  },
  // 我的页面
  {
    path: '/mine',
    name: 'Mine',
    component: () => import(/* webpackChunkName: "mine" */ '../views/Mine.vue'),
  },
  // 我的旅行
  {
    path: '/travelOrder',
    name: 'TravelOrder',
    component: () => import(/* webpackChunkName: "travelOrder" */ '../views/TravelOrder.vue'),
  },
  // 我的旅行详情页
  {
    path: '/orderDetail/:oid',
    name: 'OrderDetail',
    props: true,
    component: () => import(/* webpackChunkName: "orderDetail" */ '../views/OrderDetail.vue'),
  },
  // 我的订制
  {
    path: '/customOrder',
    name: 'CustomOrder',
    component: () => import(/* webpackChunkName: "customOrder" */ '../views/CustomOrder.vue'),
  },
  // 账号管理
  {
    path: '/admin',
    name: 'Admin',
    component: () => import(/* webpackChunkName: "admin" */ '../views/Admin.vue'),
  },
  // 修改密码
  {
    path: '/cipher',
    name: 'Cipher',
    component: () => import(/* webpackChunkName: "cipher" */ '../views/Cipher.vue'),
  },
];

const router = new VueRouter({
  routes,
});

router.beforeEach((to, from, next) => {
  window.scrollTo(0, 0);
  next();
});

export default router;
